﻿function ClientAddRole()
{
    Url=Portal.SystemWebParts.Role.Role.GetAddGroupNewUrl().value;
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    RealJumpPageRole();
}

function ClientSaveAddRole()
{
    Subject = document.getElementById("txtRole").value;
    RetValue = Portal.SystemWebParts.Role.AddRole.ServerSideAddRole(Subject).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}

function ClientDeleteRole(RoleId)
{
    Msg=Portal.SystemWebParts.Role.Role.GetConfirmDeleteMsg().value;
    if(confirm(Msg)==false)return;
    RetValue = Portal.SystemWebParts.Role.Role.ServerSideDeleteRole(RoleId).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    RealJumpPageRole();
}

function ShowClientUpdateUrlForm(RoleId)
{
    Url=Portal.SystemWebParts.Role.Role.GetShowUpdateForm(RoleId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    RealJumpPageRole();
}


function ShowFormRoleInUser(RoleId)
{
    Url=Portal.SystemWebParts.Role.Role.GetShowFormRoleInUser(RoleId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    RealJumpPageRole();
}

function ClientSaveUpdateRole(RoleId)
{
    Subject=document.getElementById("txtRole").value;
    RetValue = Portal.SystemWebParts.Role.UpdateRole.ServerSideUpdateRole(RoleId,Subject).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}


function ShowClientRoleItemUrlForm(RoleId)
{
    Url=Portal.SystemWebParts.Role.Role.GetShowRoleItemsForm(RoleId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
}

function ClientShowNewsItemForms(RoleId)
{
    Url=Portal.SystemWebParts.Role.Role.GetShowNewsItemForm(RoleId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
}



function JumPageAvailableRole(RoleId)
{
    document.getElementById("divProcessingAvailable").innerHTML=Portal.SystemWebParts.Role.RoleInUser.GetProcessingText().value;
    setTimeout("RealJumPageAvailableRole('"+RoleId+"')",10);
}

function RealJumPageAvailableRole(RoleId)
{
    PageIndex=0;
    if(document.getElementById("divSelectAvailableRole")!=null)
    {   
        PageIndex=document.getElementById("divSelectAvailableRole").selectedIndex;
    }
    Keyword=document.getElementById("txtAvailableKeyword").value;
    retValue=Portal.SystemWebParts.Role.RoleInUser.ReadingAvailableUser(RoleId,Keyword,PageIndex).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessingAvailable").innerHTML="";
    document.getElementById("divAvailableRole").innerHTML=retValue;
}







function JumPageAlreadyRole(RoleId)
{
    document.getElementById("divProcessingAlready").innerHTML=Portal.SystemWebParts.Role.RoleInUser.GetProcessingText().value;
    setTimeout("RealJumPageAlreadyRole('"+RoleId+"')",10);
}

function RealJumPageAlreadyRole(RoleId)
{
    PageIndex=0;
    if(document.getElementById("divSelectAlreadyRole")!=null)
    {   
        PageIndex=document.getElementById("divSelectAlreadyRole").selectedIndex;
    }
    Keyword=document.getElementById("txtAlreadyKeyword").value;
    retValue=Portal.SystemWebParts.Role.RoleInUser.ReadingAlreadyUser(RoleId,Keyword,PageIndex).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessingAlready").innerHTML="";
    document.getElementById("divAlreadyRole").innerHTML=retValue;
}



function AssignUserToThisRole(UserId,RoleId)
{
    retValue=Portal.SystemWebParts.Role.RoleInUser.ServerSideAddUserToRole(UserId,RoleId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    RealJumPageAvailableRole(RoleId);
    RealJumPageAlreadyRole(RoleId);
}


function RomoveUserFromThisRole(UserId,RoleId)
{
    if(confirm(Portal.SystemWebParts.Role.RoleInUser.GetConfirmDeleteMsg().value)==false)return;
    retValue=Portal.SystemWebParts.Role.RoleInUser.ServerSideRemoveUserFromRole(UserId,RoleId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    RealJumPageAvailableRole(RoleId);
    RealJumPageAlreadyRole(RoleId);
}



function JumPageRole()
{
    document.getElementById("divProcessing").innerHTML=Portal.SystemWebParts.Role.Role.GetProcessingText().value;
    setTimeout("RealJumpPageRole()",10);
}

function RealJumpPageRole()
{
    PageIndex=0;
    if(document.getElementById("divSelectPageRole")!=null)
    {   
        PageIndex=document.getElementById("divSelectPageRole").selectedIndex;
    }
    Keyword = document.getElementById("txtKeyword").value;
    OfficeCode = document.getElementById("txtOfficeCode").value;
    retValue = Portal.SystemWebParts.Role.Role.GetHtml(Keyword, OfficeCode, PageIndex).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    document.getElementById("divRoleMain").innerHTML=retValue;
}


function ShowImportFromAdFunc()
{
    Url=Portal.SystemWebParts.Role.Role.ServerSideShowImportFromAdFunc().value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    RealJumpPageRole();   
}



function ClientExecuteImport()
{
    document.getElementById("divProcessing").innerHTML=Portal.SystemWebParts.Role.ImportRoleFromAd.GetProcessingText().value;
    setTimeout("RealExecuteImport()",10);
}

function RealExecuteImport()
{
    retValue=Portal.SystemWebParts.Role.ImportRoleFromAd.ServerSideExecuteImport().value;
    document.getElementById("divProcessing").innerHTML="";
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divLog").innerHTML=retValue;
}

function ShowPermission(RoleId) {
    Url = Portal.SystemWebParts.Role.Role.GetShowFormSetPermission(RoleId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
}